package com.example.controller;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.lang.Result;
import com.example.entity.UserMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 我的消息
 *
 * @Author 林必昭
 * @Date 2019/9/4 12:22
 */

@Controller
public class UserMessageController extends BaseController{

    /**
     * 删除消息
     * @param id
     * @param all
     * @return
     */
    @ResponseBody
    @PostMapping("/message/remove")
    public Result removeMsg(Long id, boolean all) {

        QueryWrapper<UserMessage> warapper = new QueryWrapper<UserMessage>()
                .eq("to_user_id", getProfileId())
                .eq(!all,"id", id);

        //只能删除自己的消息
        boolean res = userMessageService.remove(warapper);

        return res ? Result.succ("操作成功", null, "/center/message") : Result.fail("删除失败");
    }
}
